/*
 * This DAL Role Class is user to retrieve informations from the table Role
 * The BL
 */

package sim.DAL;

import java.io.Serializable;
import java.sql.ResultSet;
//import java.sql.SQLException; // Inutiliser

/**
 *
 * @author rafik
 */

public class Role implements Serializable {

    private Integer id;
    private String roleType;

    //Constructeur vide
    public Role() {
    }
    //Constructure avec id en entree
    public Role(Integer id) {
        try {
            DBConnection db = new DBConnection();
            ResultSet rs = db.executeSql("SELECT r FROM Role r WHERE r.id = "+id);

            while (rs.next()) {
            this.id = id;
            this.roleType = rs.getString("role_type");
            }
        } catch(Exception exp){
            System.out.println(exp.getMessage());
            this.id=null;
            this.roleType = null;
        }
    }
    // Contructeur avec idn et roleType en entree
    // Pourquoi on ne fait pas de verification ici ?
    public Role(Integer id, String roleType) {
        this.id = id;
        this.roleType = roleType;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getRoleType() {
        return roleType;
    }

    public void setRoleType(String roleType) {
        this.roleType = roleType;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Role)) {
            return false;
        }
        Role other = (Role) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "sim.DAL.Role[id=" + id + "]";
    }

}
